#include <iostream>
#include "server.h"

using namespace std;

void sig_pipe(int signo);
int main(int argc,char *argv[])
{
    //注册信号
       sighandler_t ret;
       ret = signal(SIGTSTP,sig_pipe);
       if(SIG_ERR == ret)
       {
           printf("信号挂接失败\n");
           return -1;
       }
       else
           printf("信号挂接成功\n");
    server::inst()->registServer();
}

void sig_pipe(int signo)
{
    printf("catch a signal\n");
    if(signo == SIGTSTP)
    {
        printf("接收到 SIGTSTP 信号\n");
        int ret = server::inst()->closeServer();
        if(ret == 0)
            printf("成功 : 关闭套接字\n");
        else if(ret ==-1 )
            printf("失败 : 未关闭套接字\n");

        exit(1);
    }
}
